package com.itheima.controller;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author codermao
 * @date 2023/11/8 14:08
 */
@Component
@Aspect
public class MyExceptionAdvice {
    @Pointcut("execution(* com.itheima.controller..*.*(..))")
    public void pt(){}

    @Around("pt()")
    public Object around(ProceedingJoinPoint pjp){
        Object result = null;
        try {
            result = pjp.proceed();
        }catch (NullPointerException e) {
            System.out.println("这里处理NullPointerException异常");

            method01();
        }catch (Exception e) {
            System.out.println("这里处理除了NullPointerException之外的Exception异常");

            method02();
        } catch (Throwable e) {
            e.printStackTrace();
        }
        return result;
    }

    private void method01() {
    }

    private void method02() {
    }
}
